package coder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import vip.ipav.log.util.LoggerTools;

import java.util.List;

public class AbsIntegerEncoder extends
    MessageToMessageEncoder<ByteBuf> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext,
        ByteBuf in, List<Object> out) throws Exception {
        LoggerTools.getConsoleLogger().info("接受到值：{}",in.toString());
        while (in.readableBytes() >= 4) {
            //简单编码器，取绝对值
            int value = Math.abs(in.readInt());
            out.add(value);
        }
    }
}
